#include <iostream>

using namespace std;

struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};

class Solution {
public:
    ListNode* oddEvenList(ListNode* head) {
        if (head == nullptr || head->next == nullptr) {
            return head;
        }
        ListNode* ptr1 = head;
        ListNode* ptr2 = head->next;
        ListNode* ptr2_head = ptr2;
        while (ptr2 != nullptr && ptr2->next != nullptr) {
            ptr1->next = ptr1->next->next;
            ptr1 = ptr1->next;
            ptr2->next = ptr2->next->next;
            ptr2 = ptr2->next;
        }
        ptr1->next = ptr2_head;
        return head;
    }
};

int main() {
    ListNode l1(1), l2(2), l3(3), l4(4), l5(5);
    l1.next = &l2;
    l2.next = &l3;
    l3.next = &l4;
    l4.next = &l5;
    Solution solution;
    solution.oddEvenList(&l1);
    return 0;
}